unit maindbview;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dbbase, StdCtrls, Buttons, Mask, RzEdit, RzRadChk, RzButton,
  Grids, DBGrids, RzDBGrid, ExtCtrls, DB;

type
  Tmaindbviewfrm = class(TdbbaseFrm)
    procedure dbgridDrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
    Procedure IniParam;override;
    procedure QFindRcd;override;
    procedure PrintRpt;override;
    procedure FindRcd;override;
    procedure AddRcd;override;
    procedure EditRcd;override;
    procedure DelRcd;override;
    procedure CutCnnt;override;
    procedure FrmExit;override;
  end;

var
  maindbviewfrm: Tmaindbviewfrm;

implementation

{$R *.dfm}

uses
  includefile, dbmodule;

Procedure Tmaindbviewfrm.IniParam;
var
  i:integer;
begin
  for i:=0 to 7 do begin
    dbgrid.Columns[i].Title.Caption:=GetCaption('maindbviewfrm',5001+i);
  end;
  DataSource.DataSet:=dbmodulefrm.dbquery;
  with dbmodulefrm.dbquery  do begin
    active:=False;
    sql.Clear;
    sql.Add(FORMAT('Select SCALEID, '+
                   'Format(DATETIME,''%s'') As [DATE], '+
                   'Format(DATETIME,''%s'') As [TIME], '+
                   'Right(RFID,%d) As RFID, ',
                   [DateFrtStr,'HH:MM:SS',RFIDLEN]));
    sql.Add('TRAYS, PRODUCTID, FORMAT(NW,"0.00") As NW, FORMAT(GW,"0.00") As GW, ID');
    sql.add('From RECORD');
    //showmessage(sql.Text);
    execsql;
    active:=True;
    for i:=0 to 7 do begin
      dbgrid.Columns[i].FieldName:=Fields[i].FieldName;
    end;
  end;
end;

procedure Tmaindbviewfrm.QFindRcd;
begin

end;

procedure Tmaindbviewfrm.PrintRpt;
begin

end;

procedure Tmaindbviewfrm.FindRcd;
begin

end;

procedure Tmaindbviewfrm.AddRcd;
begin

end;

procedure Tmaindbviewfrm.EditRcd;
begin

end;

procedure Tmaindbviewfrm.DelRcd;
var
  tmp:string;
begin
  if IDYES=Application.MessageBox(pchar(GetCaption('Msgbox',110)),
                                  pchar(GetCaption('Msgbox',104)),MB_YESNO) then begin
    tmp:=dbgrid.DataSource.DataSet['ID'];
    with dbmodulefrm.dbquery  do begin
      active:=False;
      sql.Clear;
      sql.Add(Format('Delete from RECORD where ID=''%s''',[tmp]));
      execsql;
    end;
    IniParam;
  end;
end;

procedure Tmaindbviewfrm.CutCnnt;
begin

end;

procedure Tmaindbviewfrm.FrmExit;
begin
  Hide;
end;

procedure Tmaindbviewfrm.dbgridDrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
var
  tmp:string;
begin
  with TRzDBGrid(Sender).Canvas do begin
    fillRect(Rect);
    if (field.DataType=ftFloat) then begin
      if not (field.IsNull) then
        tmp:=format('%8.2f',[strtofloat(field.AsString)]);
      TextOut(rect.Right-textwidth(tmp)-3,rect.Top+3,tmp);
    end;
  end;
end;


end.
